﻿using LibMessage.Models;

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace LibMessage
{
    public static class NetService
    {
        /// <summary>
        /// 连接服务器
        /// </summary>
        /// <param name="server">服务器IP</param>
        /// <param name="port">端口</param>
        public static void ConnectAsync(string server, int port)
        {
            TcpClient.ConnectToServer(server, port);
        }

        public static void RegisterCallback(Action<MessagePack> connected, Action<MessagePack> disconnected, Action<MessagePack> dataReceived)
        {
            TcpClient.InitCallback(connected, disconnected, dataReceived);
        }

        public static void LoginAync(string userName)
        {
            TcpClient.SendData(new MessagePack { Cmd = "login", Data = Encoding.UTF8.GetBytes(userName) });
        }

        public static void SendDataAsync(MessagePack mp)
        {
            TcpClient.SendData(mp);
        }
    }
}